package com.xianan.xuhui.netsecurityproject.common;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.xianan.xuhui.netsecurityproject.exception.BizExceptionEnum;
import com.xianan.xuhui.netsecurityproject.exception.ErrorCode;
import com.xianan.xuhui.netsecurityproject.utils.I18nUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author xiaoli
 * @description 返回数据类型
 * @since 2025/3/25 1:07
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel
public class ResponseVo<T> implements Serializable {
    /**
     * 默认成功
     */
    @ApiModelProperty("请求是否成功(true:成功 false:失败)")
    private boolean status = true;

    /**
     * 请求返回码:0表示成功
     */
    @ApiModelProperty("请求返回码:0表示成功")
    @JsonProperty("error_code")
    private Integer errorCode = ErrorCode.SUCCESS;

    /**
     * 请求返回说明
     */
    @ApiModelProperty("请求返回说明")
    private String msg = I18nUtil.get(BizExceptionEnum.SUCCESS.getName());

    /**
     * 请求返回数据
     */
    @ApiModelProperty("请求返回数据")
    private T data;

    public ResponseVo(T data){
        this.data = data;
    }
    public ResponseVo(Integer errorCode,String msgKey){
        this.errorCode = errorCode;
        this.msg = I18nUtil.get(msgKey);
    }
    public ResponseVo(Integer errorCode,String msgKey,T data){
        this.errorCode = errorCode;
        this.msg = I18nUtil.get(msgKey);
        this.data = data;
    }
}
